package self.cloud.domain.aliyun.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource(ignoreResourceNotFound=true,value="classpath:aliyun.properties")
public class AliyunSdkConfig {

    @Value("${aliyun.sdk.accessKeyId}")
    private String accessKeyId;

    @Value("${aliyun.sdk.accessSecret}")
    private String accessSecret;

    /** Value Check */
    private boolean check(String value) {
        if(value.length() < 1) {
            return false;
        }

        char firstChar = value.charAt(0);

        if(firstChar == '<') {
            return false;
        }

        return true;
    }

    // Getter and Setter

    public String getAccessKeyId() {
        if(check(this.accessKeyId)){
            return accessKeyId;
        }
        else
        {
            throw new IllegalArgumentException("aliyun.sdk.AccessKeyId no pass check");
        }
    }

    public String getAccessSecret() {
        if(check(this.accessSecret)){
            return accessSecret;
        }
        else
        {
            throw new IllegalArgumentException("aliyun.sdk.AccessSecret no pass check");
        }
    }
}
